import 'package:app_flutter/routes.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

class AreaPage extends StatefulWidget {
  final int type;

  AreaPage({int type}) : this.type = type;

  @override
  _AreaPageState createState() => _AreaPageState(type: type);
}

class _AreaPageState extends State<AreaPage> {
  int _type;

  List<Map<String, dynamic>> maps = List();
  List<String> items = List();

  _AreaPageState({int type}) : this._type = type;
  List<String> items1 = <String>[
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'J',
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'J'
  ];
  List<String> items2 = <String>[
    'Ab',
    'Bb',
    'Cb',
    'Db',
    'Eb',
    'Fb',
  ];
  List<String> items3 = <String>[
    'Ac',
    'Bc',
    'Cc',
    'Dc',
    'Ec',
    'Fc',
    'Gc',
    'Hc',
    'Jc',
    'Ac',
  ];

  List<Widget> doWidgets() {
    setMaps(items);
    List<Widget> listTitles = List();
    for (var i = 0; i < items.length; i++) {
      listTitles.add(buildListItem(context, maps[i]));
    }
    return listTitles;
  }

  Widget buildListItem(BuildContext context, Map<String, dynamic> map) {
    return GestureDetector(
        onTap: () {
          String route = '${Routes.areaDetail}';
          Routes.router.navigateTo(context, route,
              replace: false, transition: TransitionType.fadeIn);
        },
        child: Column(
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.fromLTRB(0, 17, 0, 17),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Text('鍏村煄椹炬牎璁粌鍦�',
                          style:
                              TextStyle(color: Color(0xff333333), fontSize: 14))
                    ],
                  ),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      ImageIcon(
                        AssetImage('images/icon_school.png'),
                        size: 20,
                        color: const Color(0xff23AFDC),
                      ),
                      SizedBox(
                        width: 1,
                      ),
                      Text('钀ヤ笟$_type',
                          style:
                              TextStyle(color: Color(0xff666666), fontSize: 14))
                    ],
                  ),
                ],
              ),
            ),
            Container(
              color: Color(0xffF0F0F0),
              height: 1,
            )
          ],
        ));
  }

  @override
  Widget build(BuildContext context) {
    items = items1;
    return Container(
      margin: EdgeInsets.fromLTRB(15, 10, 15, 10),
      child: ListView.builder(
          itemCount: items == null ? 0 : items.length,
          itemBuilder: (BuildContext context, int position) {
            List<Widget> temp = doWidgets();
            return temp[position];
          }),
    );
  }

  setMaps(List<String> items) {
    maps.clear();
    for (var i = 0; i < items.length; i++) {
      Map<String, dynamic> temp = {'title': items[i], 'value': items[i]};
      maps.add(temp);
    }
  }
}
